#!/usr/bin/env python

import re, os, sys,string

#define where to read and where to output the files
sourceDir="/home/source"
destinationDir="/home/destination"

#define n number of regular expressions that needs to searched and replaced
regexes = {"orignal":"replacement","orignal":"replacement"}
      
lst = os.listdir(dir)
filelst=[]
for i in lst:
      ext=i.split(".")[len(i.split("."))-1]
      j=i.split(".")
      #control the type of source files to read	
      if ext=='txt':
        fileName = dir+"/"+i
        fileNameW = dirW+"/_new"+i
        fileR = open(fileName, 'r')
        fileW = open(fileNameW, 'w')
        l = [l for l in fileR.readlines() if l.strip()]
        for line in l: 
            for k, v in regexes.iteritems():
                regx = re.compile(str(k), re.IGNORECASE)
                line = re.sub(regx, str(v), str(line))
            fileW.write(str(line))
        fileW.close()
